﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.OleDb;
using QuanLyBongDa.HeThongLuuTru;
using QuanLyBongDa.HeThongXuLy;
using QuanLyBongDa.HeThongGiaoDien;

namespace QuanLyBongDa.HeThongLuuTru
{
    class DataAccess
    {
        protected static String _connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=QuanLyBongDa.mdb";
       //protected static String _connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=QuanLyDoiBong.mdb";
        static OleDbConnection connection;

        public static void OpenConnection()
        {
            try
            {
                connection = new OleDbConnection(_connectionString);
                connection.Open();
            }
            catch (Exception)
            {
            }
        }

        public static void CloseConnection()
        {
            if (connection != null)
            {
                connection.Close();
            }
        }

        public static DataTable ExecQuery(string sql)
        {
            OpenConnection();
            DataTable dt = new DataTable();
            OleDbCommand command = connection.CreateCommand();
            command.CommandText = sql;
            OleDbDataAdapter adapter = new OleDbDataAdapter();
            adapter.SelectCommand = command;
            adapter.Fill(dt);
            CloseConnection();
            return dt;

        }

        public static void ExecNonQuery(string sql)
        {
            OpenConnection();
            OleDbCommand command = connection.CreateCommand();
            command.CommandText = sql;
            command.ExecuteNonQuery();
        }
    }
}
